﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class SessionUtils
{
    #region Common Methods
    public static T Get<T>(string key)
    {
        if (Exist(key))
            return (T)HttpContext.Current.Session[key];
        return default(T);
    }

    public static void Set<T>(string key, T val)
    {
        HttpContext.Current.Session[key] = val;
    }

    public static void Clear(string key)
    {

        HttpContext.Current.Session.Remove(key);
    }

    public static void Clear()
    {
        HttpContext.Current.Session.Clear();
    }

    public static bool Exist(string key)
    {
        return HttpContext.Current.Session[key] != null;
    }
    #endregion
}

public class CacheUtils
{
    #region Common Methods
    public static T Get<T>(string key)
    {
        if (Exist(key))
            return (T)HttpContext.Current.Session[key];
        return default(T);
    }

    public static void Set<T>(string key, T val)
    {
        HttpContext.Current.Cache[key] = val;
    }

    public static void Clear(string key)
    {
        HttpContext.Current.Cache.Remove(key);
    }

    /// <summary>
    /// Clear all
    /// </summary>
    public static void Clear()
    {

    }

    public static bool Exist(string key)
    {
        return HttpContext.Current.Cache[key] != null;
    }
    #endregion
}